//
//  MovieTableViewCell.m
//  往昔
//
//  Created by mac on 16/2/24.
//  Copyright © 2016年 干晨威. All rights reserved.
//

#import "MovieTableViewCell.h"
#import "UIImageView+WebCache.h"

@implementation MovieTableViewCell

- (void)awakeFromNib {
    // Initialization code
}

- (void)setData:(MovieModel *)data {
    
    NSString *urlString = @"http://movie.apix.cn/fun/image/";
    if (_data != data) {
        _data = data;
        
        self.bgView.backgroundColor = [UIColor whiteColor];
        //标题
        _titleText = [[NSMutableString alloc] init];
        [_titleText appendString:_data.name];
        [_titleText appendString:@"  "];
        [_titleText appendString:_data.release_date];
        
        self.titleLabel.text = _titleText;
        //图片
        NSMutableString *url = [[NSMutableString alloc] init];
        [url appendString:urlString];
        [url appendString:_data.img];
        [self.imgView sd_setImageWithURL:[NSURL URLWithString:url]];
    }
    
    [self setCellSubviewsFrame];
}

- (void)setCellSubviewsFrame {
    //图片
    self.imgView.frame = CGRectMake(1 + kLateralSpace / 2, 1 + kVerticalSpace / 2, kPicWidth, kPicHeight);
    //标题
    CGFloat width = kScreenWidth - kPicWidth - 2 * kLateralSpace - 10;
//    CGFloat height = [WXLabel getTextHeight:kTitleTextFont width:width text:_titleText linespace:kTextLineSpace];
    self.titleLabel.frame = CGRectMake(kLateralSpace + kPicWidth, kVerticalSpace / 2 + 1, width, kPicHeight);
    //背景
    CGFloat cellHeight = kPicHeight + 2 + kVerticalSpace;
    self.bgView.frame = CGRectMake(kLateralSpace / 2, kVerticalSpace / 2, kScreenWidth - kLateralSpace, cellHeight - kVerticalSpace);
}

@synthesize bgView = _bgView;
@synthesize titleLabel = _titleLabel;
@synthesize imgView = _imgView;

- (UIView *)bgView {
    
    if (!_bgView) {
        
        _bgView = [[UIView alloc] initWithFrame:CGRectZero];
        
        _bgView.backgroundColor = [UIColor whiteColor];
        
        [self.contentView addSubview:_bgView];
    }
    
    return _bgView;
}

- (UILabel *)titleLabel {
    
    if (!_titleLabel) {
        
        _titleLabel = [[UILabel alloc] initWithFrame:CGRectZero];
        
        _titleLabel.font = [UIFont systemFontOfSize:kTitleTextFont];
        _titleLabel.numberOfLines = 0;
        _titleLabel.textColor = [UIColor blackColor];
        
        [self.contentView addSubview:_titleLabel];
    }
    
    return _titleLabel;
}

- (UIImageView *)imgView {
    
    if (!_imgView) {
        
        _imgView = [[UIImageView alloc] initWithFrame:CGRectZero];
        
        [self.contentView addSubview:_imgView];
    }
    
    return _imgView;
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
